package cn.pn.project.service;
import cn.pn.project.mapper.base.CouponDao;
import cn.pn.project.pojo.base.Coupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("/coupon")
public class CouponService {

    @Autowired
    private CouponDao couponDao;


    /**
     * 通过优惠券id查询优惠券信息
     * @param couponId
     * @return
     */
    @RequestMapping("findByCouponId")
    public Coupon findByCouponId(@RequestParam("couponId") Integer couponId) throws Exception{
        return couponDao.findByCouponId(couponId);
    }

    /**
     * 获取商品以及该商品下的优惠券
     * @param commodity 需要获取到商品的id和大类型
     * @return
     */
    @RequestMapping("findAllByCouponTypeAndReleId")
    List<Coupon> findAllByCouponTypeAndReleId(Integer typeId,Integer commodityId) throws Exception{
        return couponDao.findAllByCouponTypeAndReleId(typeId,commodityId);
    }

    /**
     * 获取当前未过期的优惠券
     * @return
     * @throws Exception
     */
    @RequestMapping("findAllCoupon")
    List<Coupon> findAllCoupon()throws  Exception{
        return couponDao.findAllCoupon();
    }
}
